package com.gcl.rabbirmq;

import com.gcl.rabbirmq.utils.RabbitMQUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Producer {



    // 先启动Consumer01然后关闭，然后再启动生产者Producer
    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();
        // 声明直连交换机
        channel.exchangeDeclare("normal_exchange", BuiltinExchangeType.DIRECT);
        // 设置消息超时时间
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();

        // 发送消息

        for (int i = 1; i < 11; i++) {
            String msg = "info" + i;
            channel.basicPublish("normal_exchange", "zhangsan",properties, msg.getBytes(StandardCharsets.UTF_8));
        }


    }




}
